<?php
//
namespace app\circle\controller\admin;

use app\circle\model\CircleMemberModel;
use app\circle\model\CircleModel;
use think\Request;

class CircleMemberController extends BaseController
{

    private $circleMemberModel;

    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->circleMemberModel = new CircleMemberModel();
    }

    /**
     * 首页
     * @return mixed
     */
    public function index()
    {
        $map        = [];
        $query      = $this->request->request();
        if($this->adminInfo['admin_power']==3){
            $circleModel = new \app\circle\model\CircleModel();
            $circleIds = $circleModel->where('admin_id',$this->adminInfo['admin_id'])->column('circle_id');
            $map['circle_id'] = ['in',$circleIds];
        }
        $circleName  = $this->request->param('circle_name');
        if (!empty($circleName)) {
            $map['circle_name'] = ['like', '%' . $circleName . '%'];
        }
        if ($this->adminInfo['admin_power']==2){
            $circleModel=new CircleModel();
            $circleIds=$circleModel->where(['dept_id'=>$this->adminInfo['dept_id']])->column('circle_id');
            $map['circle_id']=['in',$circleIds];
        }
        if ($this->adminInfo['admin_power']==3){
            $circleModel=new CircleModel();
            $circleIds=$circleModel->where(['admin_id'=>$this->adminInfo['admin_id']])->column('circle_id');
            $map['circle_id']=['in',$circleIds];
        }
        $list = $this->circleMemberModel->where($map)->paginate(12, false, ['query' => $query]);
        $this->assign('list', $list);
        return $this->fetch();
    }

    /**
     * 修改
     */
    public function edit(){
        if($this->request->isAjax()){
            $data = $this->request->param();
            $this->circleMemberModel->editData($data);
            $this->success('操作成功！','index');
        }
        $id = $this->request->param('id/d');
        $info = $this->circleMemberModel->where('id',$id)->find();
        $this->assign('info',$info);
        return $this->fetch();
    }

    /**
     * 删除
     */
    public function del(){
        $id = $this->request->param('id/d');
        $this->circleMemberModel->where('id',$id)->delete();
        $this->success('操作成功！');
    }

}
